<template>
	<view class="">
			
		<view class="nav-back">
			<top-heigth :backTitle="backTitle"></top-heigth>
		</view>
		<view class="m-t24">
			
			<view class="index-top">
				<view class="index-top-l">
					<view class="box">
						<view class="font2">可提现{{detail.staffAmount}}元，未到账{{unbillAmount}}元</view>
						<view class="font" v-if="detail">
							{{detail.tAppSupplierVo.billType == 1 ? "自动分账" : (detail.billDateEnd ? detail.billDateEnd : "请续费")}}
						</view>
						<view class="cash-but"  @click="openModal" >续费</view>
					</view>
				</view>
			</view>
			
			<uv-modal ref="modal"  :showCancelButton="true" content='' @confirm="confirm">
				<view class="alert-box">
					<h1>请输入提现金额</h1>
					<uv-input placeholder="请输入提现金额" v-model="cash" type="number" inputAlign="center" border="bottom" style="margin-top: 30rpx;"></uv-input>
				</view>
			</uv-modal>
			
			
			
			<view class="content-box ">
				<view class="public-box2" style="padding-top:10rpx; padding-bottom:10rpx;">
					<view v-if="myList.length == 0" class="kong-box">
						<uv-empty mode="" text="暂无提现明细~" icon="/static/image/kong-tixian.png"></uv-empty>
					</view>
					<view class="month-list-box">
						<view class="month-list" v-for="item in myList">
							<view class="month-list-l">
								<view>{{item.createTime}}</view>
								<view>微信</view>
							</view>
							<!-- <view v-if="item.billType != 2" class="red">+{{item.accountAmount}}</view> -->
							<view class="green">{{item.amount/100}}</view>
						</view>
						
					</view>
					
				</view>
			</view>
			
			<view style="height: 90rpx;"></view>
			
			
		</view>
	</view>
</template>

<script>
	import TopHeigth from '@/components/TopHeigth.vue'
	
	export default {
		data() {
			return {
				backTitle:"提现",
				userInfo: uni.getStorageSync('userInfo'),
				myList:'',
				startTime:'',
				endTime:'',
				detail:'',
				cash:'',
				unbillAmount: 0,
				phone: ""
			}
		},
		components: { TopHeigth },
		onLoad() {
			this.getList()
			this.getDetail()
			uni.$u.http.post('/api/shop/v1_0/tAppStaffRCA/turnTAppStaffInfoBill',{
					 staffId:this.userInfo.id,
			}).then((res) => {
				this.unbillAmount = res.data.nowOrderAmount.toFixed(2)
			})
			
			uni.$u.http.post('/api/shop/v1_0/tAppConfigRCA/turnTAppConfigInfo',{
				 configCode: 'alarm'
			}).then((res) => {
			
				this.phone = res.data.configValue
			})
		},
		methods: {
			confirm() {
				if(this.cash > this.detail.staffAmount){
					uni.showToast({
						icon: "none",
						title: '所输金额不能超账户金额'
					})
					this.cash = ''
					return false
				}
				if(this.cash < 500){
					uni.showToast({
						icon: "none",
						title: '每次提现金额不能小于500'
					})
					this.cash = ''
					return false
				}
				uni.$u.http.post('/api/shop/v1_0/tAppBillCashRCA/insertTAppBillCash',{
					staffId:this.userInfo.id,//技师id
					billAmount:this.cash, 
					billSource:2, //后两个写死
					billStatus:1,
				}).then((res) => {
					if(res.code == 200){
						this.getList()
						this.getDetail()
						uni.showToast({
							icon: "none",
							title: '提现成功'
						})
						
					}else{
						uni.showToast({
							icon: "none",
							title: res.message
						})
					}
					
					
				})
			},
			getDetail(){ // 技师详情
				uni.$u.http.post('/api/shop/v1_0/tAppStaffRCA/turnTAppStaffInfo',{
					id:this.userInfo.id,
					checkBill: true
				}).then((res) => {
					this.detail = res.data
				})
			},
			getList(){
				uni.$u.http.post('/api/shop/v1_0/tAppStaffVipOrderRCA/queryTAppStaffVipOrder',{
					staffId:this.userInfo.id,
					orderStatus: 1
				}).then((res) => {
					this.myList = res.aaData
					
				})
			},
			openModal() {
				// 请求微信支付
				uni.$u.http.post('/api/shop/v1_0/tAppStaffVipOrderRCA/pay',{
					staffId: this.userInfo.id
				}).then((res) => {
					var orderInfo = res;  //从服务器获取的订单
					uni.getProvider({
					    service: 'payment',
					    success: (res) => {
					        
							var params = {
								"appid": orderInfo.data.appId,  // 微信开放平台 - 应用 - AppId，注意和微信小程序、公众号 AppId 可能不一致
								"noncestr": orderInfo.data.nonceStr, // 随机字符串
								"package": "Sign=WXPay",        // 固定值
								"partnerid": orderInfo.data.partnerid,      // 微信支付商户号
								"prepayid": orderInfo.data.prepayid, // 统一下单订单号 
								"timestamp": orderInfo.data.timeStamp,        // 时间戳（单位：秒）
								"sign": orderInfo.data.sign // 签名，这里用的 MD5/RSA 签名
							}
							console.log("orderInfo.data", params)
							uni.requestPayment({
								"provider": "wxpay", 
								"orderInfo": params,
								success(res) {
									
								},
								fail(e) {
									console.log('支付失败:' + JSON.stringify(e));
									
								}
							})
							
					    }
					});
				})
			},
			
			
		}
	}
</script>

<style lang="scss" scoped>
	@mixin flex($direction: row) {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: $direction;
	}
	.uv-nav-slot {
		@include flex;
		align-items: center;
		justify-content: space-between;
		border-width: 0.5px;
		border-radius: 100px;
		border-color: #dadbde;
		padding: 3px 7px;
		opacity: 0.8;
	}
	.index-top{
		@include flex;
		align-items: center; 
		justify-content: flex-start;
		height: 344rpx;
		background:#fff url("/static/image/mouth.png") no-repeat ;
		background-size: 100% auto;
		border-radius:26rpx;
		margin: 0 32rpx;
		box-shadow: 0rpx 0rpx 20rpx 4rpx rgba(0,0,0,0.06);
		margin-bottom:24rpx;
		
		.index-top-l{
			width: 100%;
			text-align: center;
			.box{
				@include flex;
				flex-direction:column;
				justify-content:center;
				align-items:center;
			}
		}
		.font{
			font-weight: bold;
			font-size: 28rpx;
			color: #000;
			margin-bottom: 8rpx;
			line-height: 90rpx;
			span{
				font-size: 48rpx;
				color: #EB0C00;
			}
		}
		.font2{
			font-size: 28rpx;
			color: #999999;
		}
		.font3{
			font-size: 16rpx;
			margin-top: 5rpx;
			color: #999999;
			line-height: 50rpx;
		}
	}
	
	.month-list-box{
		.month-list-l{
			width: 60%;
			@include flex;
			align-items: center; 
			justify-content: space-between;
		}
		.month-list{
			@include flex;
			align-items: center; 
			justify-content: space-between;
			font-size: 24rpx;
			border-bottom: 2rpx solid #eee;
			padding: 26rpx 0;
			.red{
				font-weight: bold;
			}
			.green{
				color: #3CCC50;
				font-weight: bold;
			}
		}
		
	}
	.month-list-box .month-list:last-child{
		border-bottom: none;
	}
	.cash-but{
		width: 156rpx;
		height: 56rpx;
		line-height: 56rpx;
		border-radius:28rpx;
		margin-top: 24rpx;
		font-size: 24rpx;
		background: #EF4B43;
		color: #fff;
	}
	.alert-box{
		@include flex;
		flex-direction:column;
		justify-content:center;
		align-items:center;
		text-align: center;
		h1{
			font-size:32rpx;
		}
		
	}
</style>
